package org.wuyi;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class JmeterJDBC {
    public static void main(String[] args) {
        try {
            //1.加载驱动
            Class.forName("com.mysql.jdbc.Driver");
            //2.获取连接
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/jmeter", "root", "123456");  //localhost表示本地主机，3306是端口号，root是数据库的根用户，123456是数据库的密码，换成自己的即可
            String sql = "select * from student where id=2";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            ResultSet resultSet = preparedStatement.executeQuery();
            while(resultSet.next()){
                System.out.println(resultSet.getInt("id"));
                System.out.println(resultSet.getInt("age"));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
